﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Hi_Baidu
{
    /// <summary>
    ///     提供指定尝试次数的Timer类
    /// </summary>
    class TO_Timer : System.Timers.Timer, IMetaData
    {
        private int tryCount;
        private int tryIndex;
        /// <summary>
        ///     总共重试次数(如果为-1则代表永久尝试)
        /// </summary>
        [DefaultValue(0)]
        public int TryCount
        {
            get { return tryCount; }
            set { tryCount = value; }
        }

        /// <summary>
        ///     当前已经重试的次数
        /// </summary>
        [DefaultValue(0)]
        public int TryIndex
        {
            get { return tryIndex; }
            set { tryIndex = value; }
        }


        #region 'TimeOut' event definition code

        // Private delegate linked list (explicitly defined)
        private EventHandler<System.EventArgs> TimeOutEventHandlerDelegate;

        /// <summary>
        ///     TODO: Describe the purpose of this event here
        /// </summary>
        public event EventHandler<System.EventArgs> TimeOut
        {
            // Explicit event definition with accessor methods
            add
            {
                TimeOutEventHandlerDelegate = (EventHandler<System.EventArgs>)Delegate.Combine(TimeOutEventHandlerDelegate, value);
            }
            remove
            {
                TimeOutEventHandlerDelegate = (EventHandler<System.EventArgs>)Delegate.Remove(TimeOutEventHandlerDelegate, value);
            }
        }

        /// <summary>
        ///     This is the method that is responsible for notifying
        ///     receivers that the event occurred
        /// </summary>
        protected virtual void OnTimeOut(System.EventArgs e)
        {
            if (TimeOutEventHandlerDelegate != null)
            {
                TimeOutEventHandlerDelegate(this, e);
            }
        }

        #endregion //('TimeOut' event definition code)

        #region IMetaData 成员

        private String key;
        public string Key
        {
            get
            {
                return key;
            }
            set
            {
                key = value;
            }
        }

        #endregion
    }
}
